<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>添加用户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="/themes/admin/css/font.css">
    <link rel="stylesheet" href="/themes/admin/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="/themes/admin/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/themes/admin/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form" action="">
                        <div class="layui-form-item">
                            <label class="layui-form-label">用户组</label>
                            <div class="layui-input-inline">
                                <select name="group_id" id="userGroup" lay-verify="required">
                                    <option value=""></option>
                                    {volist name="groupList" id="vo"}
                                    <option value="{$vo.group_id}">{$vo.name}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <input type="hidden" name="uid" value="{$userInfo.uid|default=''}">
                        <div class="layui-form-item">
                            <label class="layui-form-label">用户名</label>
                            <div class="layui-input-inline">
                                <input type="text" value="{$userInfo.username|default=''}" name="username" required  lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-form-mid layui-word-aux">*必填</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">密码</label>
                            <div class="layui-input-inline">
                                <input type="text"  name="password" placeholder="请输入密码" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-form-mid layui-word-aux">*必填</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">邮箱</label>
                            <div class="layui-input-inline">
                                <input type="text" value="{$userInfo.email|default=''}" name="email" required  lay-verify="required" placeholder="请输入邮箱" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-form-mid layui-word-aux">*必填</div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use('form', function(){
        var form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function(data){
            $.ajax({
                type:"POST",
                data:data.field,
                url:"/admin/user/userAdd",
                success:function (e) {
                    if (e.code == 1){
                        layer.msg(e.msg)
                        setTimeout(function () {
                            parent.location.reload();
                        },1500)
                    }else{
                        layer.msg(e.msg)
                    }
                }
            });
            return false;
        });

        //自动渲染用户所属组
        var groupId = "{$userInfo.group_id|default=''}";
        var select = 'dd[lay-value=' + groupId + ']';
        $("#userGroup").siblings("div.layui-form-select").find('dl').find(select).click();
    });
</script>
</body>
</html>
